package com.admission.web;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.admission.model.CollegeDetail;
import com.admission.service.CollegeFormManager;

@Namespace("/base")
@Results({@Result(name = CrudActionSupport.RELOAD, location = "/base/index.action", type = "redirect") })
public class CollegeDetailAction extends CrudActionSupport<CollegeDetail> {

	private static final long serialVersionUID = 1L;
	private String ticketNum;
	private String IdNum;
	private CollegeFormManager collegeFormManager;
	private String province;

	public String getInfo() throws IOException {
		String path = ServletActionContext.getServletContext().getRealPath(
				"/WEB-INF");
		path += "/xml/collegedetail-" + IdNum + ticketNum + ".xml";
		File f = new File(path);
		if (!f.exists()) {
			Struts2Utils.renderText("0");
		} else {
			FileReader fr = new FileReader(f);// 创建文件输入流
			BufferedReader in = new BufferedReader(fr);// 包装文件输入流，可整行读取
			String line;
			String s = "";
			while ((line = in.readLine()) != null) {
				s += line;
			}
			Struts2Utils.renderText(s.replaceAll(" ", "").replaceAll("><", "> <"));
		}

		return null;
	}
	
	public String getPro() throws IOException {
		String path = ServletActionContext.getServletContext().getRealPath(
				"/WEB-INF");
		path += "/xml/collegeprovince-" + province + ".xml";
		File f = new File(path);
		if (!f.exists()) {
			Struts2Utils.renderText("0");
		} else {
			FileReader fr = new FileReader(f);// 创建文件输入流
			BufferedReader in = new BufferedReader(fr);// 包装文件输入流，可整行读取
			String line;
			String s = "";
			while ((line = in.readLine()) != null) {
				s += line;
			}
			Struts2Utils.renderText(s.replaceAll(" ", "").replaceAll("><", "> <"));
		}

		return null;
	}

	
	public CollegeDetail getModel() {
		return null;
	}

	@Override
	public String list() throws Exception {
		if(collegeFormManager.checkConsult().equals("1"))
			return 	SUCCESS;
		else
			return "fail";
	}

	@Override
	public String input() throws Exception {
		return RELOAD;
	}

	@Override
	public String save() throws Exception {
		return RELOAD;
	}

	@Override
	public String delete() throws Exception {
		return RELOAD;
	}

	@Override
	protected void prepareModel() throws Exception {

	}

	public String getTicketNum() {
		return ticketNum;
	}

	public void setTicketNum(String ticketNum) {
		this.ticketNum = ticketNum;
	}

	public String getIdNum() {
		return IdNum;
	}

	public void setIdNum(String idNum) {
		IdNum = idNum;
	}


	public CollegeFormManager getCollegeFormManager() {
		return collegeFormManager;
	}

	@Autowired
	public void setCollegeFormManager(CollegeFormManager collegeFormManager) {
		this.collegeFormManager = collegeFormManager;
	}


	public String getProvince() {
		return province;
	}


	public void setProvince(String province) {
		this.province = province;
	}

}
